home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / ehdemo.zip / INDENTX.CB < prev    next >
Lisp/Scheme  |  1991-02-21  |  4KB  |  144 lines

  1. /*
  2. **     BRIEF -- Basic Reconfigurable Interactive Editing Facility
  3. **
  4. **     Written by Dave Nanian and Michael Strickman.
  5. */
  6.  
  7. /*
  8. **     indentx.cb:
  9. **
  10. **     These macros allow control of the automatic indenting feature of
  11. ** Brief.  They work on a buffer by buffer basis, by altering the local
  12. ** keyboard (as determined by the BPACKAGES settings).  These macros
  13. ** do NOT care what langauges are used, or even if the <Enter> key is
  14. ** ever really set to anything other than 'self_insert'.
  15. **
  16. **    This package, particularly 'indentx' was developed for the cut &
  17. ** paste feature of Curtis Palm/SofSolution's "Expert Help Hypertext
  18. ** Search Engine (tm)".  I assumed that the engine will be able to call
  19. ** the indentx macro before and after the cut & paste by stuffing
  20. ** "<F10>indentx 1" into the keyboard buffer.  The 1 argument suppresses
  21. ** text messages during the 'automated' operation.
  22. **
  23. **    By limiting the toggle macro name to 'indentx' the user doesn't
  24. ** even have to add an 'autoload' entry to his initials macro.  Of
  25. ** course, if an 'autoload' line is added, then the other macros can be
  26. ** used before a call to 'indentx' is issued.
  27. **
  28. **    Suggested 'autoload':
  29. **
  30. **    (autoload "indentx", "indentx", "inq_indent", "indent_off", "indent_on");
  31. **
  32. **
  33. **    Known Bugs
  34. **    ----------
  35. **    This package assumes indenting will be re-enabled before indenting
  36. ** is turned off in another buffer.  The the old 'local_keyboard' handle
  37. ** is stored in a global variable, and thus this package is not reentrant.
  38. ** In practice, this is not much of a limitation.
  39. **
  40. **
  41. **    History
  42. **    -------
  43. **    91.02.19 - Mitchell A Smith:  created
  44. **               can be reached via:
  45. **                 SofSolutions BBS,      user id 'msmith'
  46. **                 Solution Systems BBS,  user id 'mas'
  47. **                 snail mail: 61 Greenmeadow Ave, Thousand Oaks, CA 91320
  48. */
  49.  
  50. /* Global Variables *******************/
  51. int _oldLocalKeyboard;
  52.  
  53. /* Function Prototypes ****************/
  54. void _init (void);
  55. void indent_off (void);                /* set indenting off */
  56. void indent_on (void);                 /* restore indenting */
  57. int  inq_indent (void);                /* get indenting state */
  58. int  indentx (~int);                   /* toggle indenting state */
  59.  
  60. /****************************************************************************/
  61. void _init (void)
  62. {
  63.    /* set the global variable, in case the user calls 'indent_on()'
  64.    ** without first calling 'indent_off()'.
  65.    */
  66.    _oldLocalKeyboard = inq_local_keyboard();
  67. }
  68.  
  69.  
  70. /* indent_off:
  71. **
  72. ** Turn off indenting.
  73. */
  74. void indent_off (void)
  75. {
  76.    int newLocalKeyboard;
  77.  
  78.    _oldLocalKeyboard = inq_local_keyboard();
  79.    
  80.    keyboard_push();
  81.     assign_to_key("<Enter>", "self_insert");
  82.     newLocalKeyboard = inq_keyboard();
  83.    keyboard_pop(1);
  84.  
  85.    use_local_keyboard(newLocalKeyboard);
  86. }
  87.  
  88. /* indent_on:
  89. **
  90. ** Turn on (restore) indenting.
  91. */
  92. void indent_on (void)
  93. {
  94.    use_local_keyboard(_oldLocalKeyboard);
  95. }
  96.  
  97. /* inq_indent:
  98. **
  99. ** Get the status of 'indenting', 1 if active, 0 if inactive;
  100. ** also show status as a text message if 'inq_indent' is called from
  101. ** the keyboard, or with a non-zero argument.
  102. */
  103. int inq_indent (~int)
  104. {
  105.    int showMessage;
  106.    string indentMacro = inq_assignment ("<Enter>");
  107.    int indentState = (indentMacro != "self_insert");
  108.  
  109.    /* user called from keyboard, report status in a text message */
  110.    if (inq_called() == "" || (get_parm (0, showMessage) && showMessage))
  111.       {
  112.       if (indentState)
  113.          message("Indenting ON  (using '%s' macro).", indentMacro);
  114.       else
  115.          message("Indenting off.");
  116.       }
  117.  
  118.    return (indentState);               /* return current state */
  119. }
  120.  
  121.  
  122. /* indentx:
  123. **
  124. ** Toggle the indenting state, returning the previous indentign state.
  125. ** Also show the new status as a text message if 'indentx' is called
  126. ** from the keyboard without any argument.
  127. */
  128. int indentx (~int)
  129. {
  130.    int noMessage;
  131.    int indentState = inq_indent(0);
  132.  
  133.    if (indentState)
  134.       indent_off();
  135.    else
  136.       indent_on();
  137.  
  138.    /* user called from keyboard, report status in a text message */
  139.    if (inq_called() == "" && ! get_parm (0, noMessage))
  140.       inq_indent(1);
  141.  
  142.    return (indentState);               /* return previous state */
  143. }
  144.